package com.ykdl.member.kid.beans;

import java.io.Serializable;

import org.json.JSONObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import net.wxxr.http.interfaces.IJsonParser;

public class VersionUpgrade implements Serializable, IJsonParser {

	private static final long serialVersionUID = 8627210017111532339L;

	private boolean force_update = false;
	private  LastVersion latest_version = null;
	private boolean isExpired = false;
	private String desc;
	private String error;
	public String getDesc() {
		return desc;
	}

	public String getError() {
		return error;
	}

	public class LastVersion implements Serializable{
		private static final long serialVersionUID = -4743259956801546818L;
		private String app_url = null;
		private float version ;
		public String getApp_url() {
			return app_url;
		}
		public void setApp_url(String app_url) {
			this.app_url = app_url;
		}
		public float getVersion() {
			return version;
		}
		public void setVersion(float version) {
			this.version = version;
		}
		
	}
	public boolean isForce_update() {
		return force_update;
	}

	public void setForce_update(boolean force_update) {
		this.force_update = force_update;
	}
	
	public LastVersion getLatest_version() {
		return latest_version;
	}

	public void setLatest_version(LastVersion latest_version) {
		this.latest_version = latest_version;
	}
	public boolean isExpired() {
		return isExpired;
	}
	public void setExpired(boolean isExpired) {
		this.isExpired = isExpired;
	}
	
	@Override
	public IJsonParser parse(String json) throws Exception {
		Gson   gson = null;
		if(null != json){
			GsonBuilder b = new GsonBuilder();
			gson  = b.create();
			VersionUpgrade  bean = new VersionUpgrade();
			if(json.startsWith("{") && json.endsWith("}")
					&& new JSONObject(json).has("error")
					&& new JSONObject(json).getInt("error") == 20007){
				bean.setExpired(true);
				return bean;
			}
			return gson.fromJson(json, VersionUpgrade.class);
		}
		return null;
	}

}
